//
//  SMMineMenuCell.m
//  SteelRecover
//
//  Created by 郑渊文 on 2025/9/17.
//

#import "SMMineMenuCell.h"
#import <Masonry/Masonry.h>

@interface SMMineMenuCell ()
@property(nonatomic, strong) UIView *card;
@property(nonatomic, strong) UIImageView *icon;
@property(nonatomic, strong) UILabel *titleL;
@end

@implementation SMMineMenuCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self=[super initWithFrame:frame]) {
        self.contentView.backgroundColor = UIColor.clearColor;
        _card = [UIView new];
        _card.backgroundColor = UIColor.secondarySystemBackgroundColor;
        _card.layer.cornerRadius = 12;
        _card.layer.masksToBounds = YES;
        [self.contentView addSubview:_card];
        [_card mas_makeConstraints:^(MASConstraintMaker *make){
            make.edges.equalTo(self.contentView);
        }];

        _icon = [UIImageView new];
        _icon.contentMode = UIViewContentModeScaleAspectFit;
        [_card addSubview:_icon];

        _titleL = [UILabel new];
        _titleL.font = [UIFont systemFontOfSize:13];
        _titleL.textColor = UIColor.labelColor;
        _titleL.textAlignment = NSTextAlignmentCenter;
        [_card addSubview:_titleL];

        [_icon mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.equalTo(self.card).offset(12);
            make.centerX.equalTo(self.card);
            make.width.height.mas_equalTo(28);
        }];
        [_titleL mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.equalTo(self.icon.mas_bottom).offset(8);
            make.left.equalTo(self.card).offset(8);
            make.right.equalTo(self.card).offset(-8);
            make.bottom.equalTo(self.card).offset(-10); // ✅ 增加底部约束，避免被裁
        }];
    }
    return self;
}

- (void)configureWithTitle:(NSString *)title symbol:(NSString *)sfSymbolName {
    _titleL.text = title ?: @"";
    if (@available(iOS 13.0, *)) {
        UIImageSymbolConfiguration *cfg = [UIImageSymbolConfiguration configurationWithPointSize:20 weight:UIImageSymbolWeightMedium];
        _icon.image = [UIImage systemImageNamed:sfSymbolName withConfiguration:cfg];
        _icon.tintColor = [UIColor colorWithRed:0.23 green:0.56 blue:0.96 alpha:1.0];
    } else {
        _icon.image = nil;
        _icon.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        _icon.layer.cornerRadius = 6;
        _icon.layer.masksToBounds = YES;
    }
}

@end

